package com.yanyeori.framework.websocket.message;

import lombok.Getter;
import org.springframework.util.StringUtils;

/**
 * Message 主题
 *
 * @author chenkuan 2021/6/3
 */
@Getter
public enum WsTopicEnum {
    HEARTBEAT("ws_topic_heartbeat", "Heartbeat"),
    SUBSCRIBE("ws_topic_subscribe", "Subscribe"),
    UNSUBSCRIBE("ws_topic_unsubscribe", "Unsubscribe");

    private final String type;
    private final String msg;

    WsTopicEnum(String type, String msg) {
        this.type = type;
        this.msg = msg;
    }

    public static WsTopicEnum getByType(String type) {
        if (StringUtils.isEmpty(type)) {
            return null;
        }
        for (WsTopicEnum en : WsTopicEnum.values()) {
            if (en.getType().equals(type)) {
                return en;
            }
        }
        return null;
    }
}
